// poj1275
// 题意：给定一天24个小时每个小时需要的员工数目，然后给定n个应聘的员工
//       以及应聘的时间，每个员工从应聘时间开始工作8小时。
//       问在满足每小时员工工作情况的条件下，最少可以有几个员工。
//
// 题解：为避免负数，时间计数1～24。令：
//       R[i] i时间需要的人数 （1 <= i <= 24）
//       T[i] i时间应聘的人数 （1 <= i <= 24）
//       x[i] i时间录用的人数 （0 <= i <= 24），其中令x[0] = 0
//       needed[i] 表示从i-1 ~ i这一个小时需要的员工，
//       applied[i] 表示第 i 个小时来应聘的员工个数。
//
//       记s[i] = x[0] + x[1] + ... + x[i] （0 <= i <= 24），
//       那么需要满足以下方程:
//       (1) s[i - 1] - s[i] <= 0			(1 <= i <= 24)
//       (2) s[i] - s[i - 1] <= applied[i]	(1 <= i <= 24)
//       (3) s[i - 9] - s[i - 1] <= -needed[i] (i >= 9)
//       (4) s[i + 15] - s[i - 1] <= sum - needed[i] (i < 9)
//       (5) s[24] - s[0] <= -sum
//       sum是要二分的答案。
//
// run: time $exec < input
#include <iostream>
#include <algorithm>
#include <deque>
#include <cstring>
#include <vector>

template <class T>
struct shortest_path_faster_algorithm
{
	typedef T value_type;
	typedef int size_type;

	struct edge {
		edge(size_type from, size_type to, value_type cost) : from(from), to(to), cost(cost) {}
		size_type from, to;
		value_type cost;
	};

	typedef std::vector<edge> adj_edge;
	typedef typename adj_edge::iterator edge_iter;
	typedef std::vector<adj_edge> graph_type;
//	enum { inf = 1 << 28 };
	value_type static const inf = 1 << 28;

	shortest_path_faster_algorithm(size_type n) : n(n)
	{
		graph.resize(n);
		dist.resize(n);
		in_queue.resize(n);
		count_into_que.resize(n);
	}

	void add_edge(size_type from, size_type to, value_type cost)
	{
		graph[from].push_back(edge(from, to, cost));
	}

	value_type spfa(size_type source, size_type target)
	{
		std::fill(dist.begin(), dist.end(), +inf);
		std::fill(in_queue.begin(), in_queue.end(), false);
		std::fill(count_into_que.begin(), count_into_que.end(), 0);
		std::deque<value_type> relaxed(1, source);
		dist[source] = 0;
		in_queue[source] = true;
		count_into_que[source]++;
		while (!relaxed.empty()) {
			size_type now = relaxed.front();
			in_queue[now] = false;
			relaxed.pop_front();

			for (edge_iter it = graph[now].begin(); it != graph[now].end(); ++it) {
				size_type v = it->to;
				value_type c = it->cost;
				if (dist[v] > dist[now] + c) {
					dist[v] = dist[now] + c;
					if (!in_queue[v]) {
						if (count_into_que[v] >= n) return -inf;
						if (!relaxed.empty() && dist[v] < dist[relaxed.front()])
							relaxed.push_front(v);
						else
							relaxed.push_back(v);
						in_queue[v] = true;
						count_into_que[v]++;
					}
				}
			}
		}
		return dist[target];
	}

private:
	graph_type graph;
	size_type n;
	std::vector<size_type> count_into_que;
	std::vector<value_type> dist;
	std::vector<char> in_queue; // FIXME std::vector<bool>;
};

int const maxn = 25;
int needed[maxn];
int applied[maxn];

bool judge(int sum)
{
	int n = 25;
	shortest_path_faster_algorithm<int> sp(n);
	for (int i = 1; i < n; i++) sp.add_edge(i - 1, i, 0);
	for (int i = 1; i < n; i++) sp.add_edge(i, i - 1, applied[i]);
	sp.add_edge(0, 24, -sum);

	for (int i = 1; i < n; i++) {
		if (i >= 9)
			sp.add_edge(i - 9, i - 1, -needed[i]);
		else
			sp.add_edge(i + 15, i - 1, sum - needed[i]);
	}
	return sp.spfa(0, 24) != -sp.inf;
}

int main()
{
	std::ios::sync_with_stdio(false);
	int T; std::cin >> T;
	while (T--) {
		std::memset(applied, 0, sizeof(applied));
		int n = 24, m, sum = 0;
		for (int i = 1; i <= n; i++) std::cin >> needed[i];
		for (int i = 1; i <= n; i++) sum += needed[i];
		std::cin >> m;
		for (int i = 0, h; i < m; i++) {
			std::cin >> h;
			if (!h) h = 24;
			applied[h]++;
		}
		int l = 0, r = m;
		while (l + 1 <= r) {
			int mid = (l + r) / 2;
			if (judge(mid)) r = mid;
			else			l = mid + 1;
		}
		if (judge(l) || judge(r)) {
			if (judge(l)) r = l;
			std::cout << r << '\n';
		} else
			std::cout << "No Solution\n";
	}
}

